package uplb.ics.cs190.e2d.display;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import uplb.ics.cs190.e2d.graphics.AWTImage;
import uplb.ics.cs190.e2d.graphics.Color;
import uplb.ics.cs190.e2d.graphics.Image;

public class J2SEGraphics implements Graphics {

	protected Graphics2D graphics;
	
	public J2SEGraphics(Graphics2D g) {
		this.graphics = g;
	}
	
	public J2SEGraphics() {
		this(null);
	}
	
	public Graphics2D getGraphics() {
		return this.graphics;
	}
	
	public void setGraphics(Graphics2D g) {
		this.graphics = g;
	}

	@Override
	public void setColor(Color color) {
		this.graphics.setColor(new java.awt.Color(color.getRed(),
				color.getGreen(), color.getBlue(), color.getAlpha()));
	}

	@Override
	public void fillRect(int x, int y, int width, int height) {
		this.graphics.fillRect(x, y, width, height);
	}

	@Override
	public void drawImage(Image image, int x, int y) {
		BufferedImage buff = (BufferedImage) ((AWTImage) image).getImage();
		this.graphics.drawImage(buff, x, y, null);
	}

	@Override
	public Color getColor() {
		return new Color(
				this.graphics.getColor().getRed(), 
				this.graphics.getColor().getGreen(), 
				this.graphics.getColor().getBlue(),
				this.graphics.getColor().getAlpha());
	}

	@Override
	public void drawRect(int x, int y, int width, int height) {
		this.graphics.drawRect(x, y, width, height);
	}

	@Override
	public void clearRect(int x, int y, int width, int height) {
		this.graphics.clearRect(x, y, width, height);
	}

	@Override
	public void drawLine(int x1, int y1, int x2, int y2) {
		this.graphics.drawLine(x1, y1, x2, y2);
	}

	@Override
	public void drawString(String string, int x, int y) {
		this.graphics.drawString(string, x, y);
	}
}